#include "Publisher.h"

Publisher::Publisher() : m_Id ( 100 )
{

}

Publisher::~Publisher()
{

}

int Publisher::add ( IrCallback f )
{
	boost::unique_lock<boost::mutex> lock(m_Mutex);
	m_Id++;
	m_Listeners[m_Id] = f;
	return m_Id;
}

void Publisher::remove ( int id )
{
	boost::unique_lock<boost::mutex> lock(m_Mutex);
	m_Listeners.erase(id);
}

void Publisher::call ( DWORD protocol, DWORD key, DWORD repeat, const char * name )
{
	printf("%d %d %d %s\n", protocol, key, repeat, name );
	boost::unique_lock<boost::mutex> lock(m_Mutex); // some potential for deadlock here as we call out of this function... redo.
	
	for(RegMap::iterator it = m_Listeners.begin() ; it != m_Listeners.end(); it++ )
	{		
		it->second(protocol,key, repeat, name);		
	}	
}


